import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;


public class TeamManager implements Iterable<HockeyPlayer >{
	private List<HockeyPlayer> roster;
	private String teamName;
	
	public TeamManager(String inTeamName) {
		roster = new ArrayList<HockeyPlayer>();
		teamName = inTeamName;
	}
	
	public void addPlayer(HockeyPlayer aPlayer) {
		roster.add(aPlayer);
	}
	
	public String getTeamName() {
		return teamName;
	}
	
	public int size() {
		return roster.size();
	}
	
	public void addGoal(HockeyPlayer looksLikeAPlayer) {
		int positionOnList = roster.indexOf(looksLikeAPlayer);
		if(positionOnList == -1) {
			return;
		}
		
		HockeyPlayer actualPlayer = roster.get(positionOnList);
		actualPlayer.addGoal();
	}
	
	public HockeyPlayer get(int positionOnList) {
		return roster.get(positionOnList);
	}
	
	public Iterator<HockeyPlayer> iterator() {
		Collections.sort(roster);
		Collections.reverse(roster);
		return roster.iterator();
	}
	
	public int getTotalGoalsScored() {
		int totalScored = 0;
		
		for(HockeyPlayer aPlayer : roster) {
			int goalsForThisPlayer = aPlayer.getGoals();
			totalScored += goalsForThisPlayer;
		}
		
		return totalScored;
	}

}
